export const customNav = targetPath => {
    const pages = getCurrentPages()
    console.log(targetPath)
    console.log('----------current pages',pages)
    let delta = -1
    for (let i = 0; i < pages.length;i++) {
        if ( targetPath === `/${pages[i].route}`) {
            delta = i + 1
            break
        }
    }
    // 查找目标页面是否已经被访问过
    const targetPage = pages.find(page => targetPath.includes(page.route))
    if (targetPage) {
        // 如果已经被访问过，使用navigateBack返回
        uni.navigateBack({
            delta: pages.length - delta
        }).then(r => {
            console.log('跳转成功',r.errMsg)
        })
    } else {
        if (pages.length >= 10) {
            uni.redirectTo({
                url: targetPath
            }).then(r => {
                console.log('跳转成功',r.errMsg)
            })
        } else {
            uni.navigateTo({
                url: targetPath
            }).then(r => {
                console.log('跳转成功',r.errMsg)
            })
        }
    }
}
